package com.example.hallserver.controller;

import com.example.common.MjDemo;
import com.example.common.User;
import com.example.hallserver.ChessClient;
import com.example.hallserver.config.UserConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created on 2020/2/17.
 *
 * @author Grak
 * @since 1.0
 */
@RestController
public class UserController {

    @Autowired
    private UserConfig config;

    @Autowired
    private ChessClient chessClient;

    @Value("${server.port}")
    private String port;

    @GetMapping("/getUser")
    public String getUser(){
        return "port="+ port + "," + config.toString();
    }

    @GetMapping("/getUserOnly")
    @CrossOrigin(allowCredentials = "true") //允许cook跨域
    public User getUserOnly(){
        User user = new User();
        user.setName(config.getName());
        user.setAge(Integer.valueOf(config.getAge()));
        user.setDescript(config.getDescript());
        return user;
    }

    @GetMapping("/getUserForChess")
    public MjDemo getUserForChess(){
        return chessClient.getChessOnly();
    }
}
